var form
$(document).ready(function () {
  initLayui()
  initSize()
})

function initLayui() {
  layui.use(function () {
    form = layui.form;

    // 登录
    form.on('submit(login)', function (data) {
      $.ajax({
        url: '/rest/dtchat/login',
        type: "POST",
        contentType: "application/json",
        data: JSON.stringify({
          "account": data.field.account,
          "password": data.field.password
        }),
        success: function (data) {
          var status = data.status;
          var data = data.result;
          if (status == 200) {
            localStorage.setItem('userInfo', JSON.stringify(data));
            localStorage.setItem('sessionId', JSON.stringify(data.sessionId));
            window.location.href = "index.html";
          } else {
            layer.msg('用户名或密码错误');
          }
        },
        error: function (result) {

        }
      })
    });
    return false;
  })
}

function initSize() {
  //适应不同分辨率
  let fontSize;
  resize();
  window.onresize = resize;

  function resize() {

    let winW = window.innerWidth;

    if (winW < 1366) {
      winW = 1366;
    }
    fontSize = winW / 1920 * 100
    document.getElementsByTagName('html')[0].style.cssText = "font-size:" + fontSize + "px";
  }
}

document.addEventListener('keyup', function (event) {
  if (event.keyCode === 13) {
    $('#login-btn').click()
  }
});